package com.skyworth.web.ordermenu;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by cody on 2016/8/23.
 */
@Repository
public interface OrderMenuRepository extends PagingAndSortingRepository<OrderMenuModel,Long>{

    @Query(value = "select a.* from ff_map_order_menu a,ff_order b,ff_parent_order c where a.order_id=b.id and b.parent_id=c.id and c.id=?1",nativeQuery = true)
    List<OrderMenuModel> findByOrderId(long id);

    @Query(value = "select a.* from ff_map_order_menu a,ff_order b,ff_parent_order c where a.order_id=b.id and b.parent_id=c.id and b.state=1 and c.id=?1",nativeQuery = true)
    List<OrderMenuModel> findByPayOrderId(long id);

    @Query(value = "select a.* from ff_map_order_menu a,ff_order b,ff_parent_order c where a.order_id=b.id and b.parent_id=c.id and b.state=0 and c.id=?1",nativeQuery = true)
    List<OrderMenuModel> findByNoPayOrderId(long id);


    @Query(value = "select a.* from ff_map_order_menu a where  a.id=?1 and a.remove_flag=0",nativeQuery = true)
    List<OrderMenuModel> findBySubOrderId(long id);

}
